import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: GodK
 * Date: 2024-03-30
 * Time: 19:27
 */
public class Main {
    public static int romanToInt(String s) {
        Stack<Integer> stack = new Stack<>();
        for(int i = 0 ;i < s.length(); i++){
            char ch = s.charAt(i);
            switch(ch){
                case 'I':
                    stack.push(1);
                    break;
                case 'V':
                    stack.push(5);
                    break;
                case 'X':
                    stack.push(10);
                    break;
                case 'L':
                    stack.push(50);
                    break;
                case 'C':
                    stack.push(100);
                    break;
                case 'D':
                    stack.push(500);
                    break;
                case 'M':
                    stack.push(1000);
                    break;
            }
        }
        int sum = 0;
        int b = 0;
        for(int i = 0 ;i < s.length(); i++){
            int a = stack.pop();
            if(sum==0 || b == a || sum < a){
                sum += a;
                b = a;
            }else{
                sum -= a;
            }
        }
        return sum;
    }

    public static String longestCommonPrefix1(String[] strs) {
        if(strs == null || strs.length == 0)return "";
        String s = strs[0];
        for(int i = 1;i < strs.length ; i++){
            s = longestCommonPrefix1(s ,strs[i]);
            if(s.length() == 0)break;
        }
        return s;
    }
    public static String longestCommonPrefix1(String s1,String s2){
        int min = Math.min(s1.length(),s2.length());
        int index = 0;
        while(index < min && s1.charAt(index)==s2.charAt(index)){
            index++;
        }
        return s1.substring(0,index);
    }
    public static void main(String[] args) {
        System.out.println(romanToInt("III"));
        String[] strings1 = new String[]{"flower","flow","flight"};
        System.out.println(longestCommonPrefix1(strings1));
    }
}
